import React from 'react';
import { Button, Modal, Form, Input, Radio } from 'antd';
import { injectIntl } from 'react-intl';
import DepartmentPicker from '../../components/pickCity/departmentPicker';

const FormItem = Form.Item;
const createForm = Form.create;
class modifyStaffForm extends React.Component {

    validatePhone=(rule, value, callback)=>{
        const common = this.props.intl.messages.common;
        let myreg=/^1[3|4|5|7|8][0-9]{9}$/;
            if (value&&!myreg.test(value)) {
                callback(common.PleaseEnterCorrectPhone);
            } else {
                callback();
            }
        }
    validateAcccount=(rule, value, callback)=>{
        const common = this.props.intl.messages.common;
        let myreg=/^1[3|4|5|7|8][0-9]{9}$/;
        if (value&&!myreg.test(value)) {
            callback(common.usernameInPhoneFormat);
        } else {
            callback();
        }
    }

        render() {
            const common = this.props.intl.messages.common;
            const { visible, onCancel,onCreate, form } = this.props;
            const { getFieldDecorator } = form;
            return (
                <Modal
                    visible={visible}
                    title={common.modifyInfo}
                    okText="确定"
                    onCancel={onCancel}
                    onOk={onCreate}
                >
                    <Form layout="vertical">
                        <FormItem label={common.loginAccount}>
                            {getFieldDecorator('account', {
                                rules: [
                                    {validator: this.validateAcccount}
                                    ],
                                initialValue:this.props.selectAccount.account,
                                validateTrigger:'onBlur'
                            })(
                                <Input disabled/>
                            )}
                        </FormItem>
                        <FormItem label={common.username}>
                            {getFieldDecorator('name',{
                                initialValue:this.props.selectAccount.name,
                            })(
                                <Input />
                            )}
                        </FormItem>
                        <FormItem label={common.phone}>
                            {getFieldDecorator('phone',
                                {
                                    rules: [
                                        {validator: this.validatePhone}
                                        ],
                                    validateTrigger:'onBlur',
                                    initialValue:this.props.selectAccount.phone,
                                })(
                                <Input />
                            )}
                        </FormItem>
                        <FormItem label='所属部门'>
                            {getFieldDecorator('org',
                                {initialValue:this.props.selectAccount.org,
                                })(
                                <DepartmentPicker />
                            )}
                        </FormItem>
                    </Form>
                </Modal>
            );
        }
    }

modifyStaffForm=createForm()(modifyStaffForm);
export default injectIntl(modifyStaffForm)